#pragma once
#include "AlgorithmCommon.h"

class IInterpolator
{
public:
	virtual void Initialize(IDataProvider* pProvider) = 0;
	virtual float Interpolate(void* pos) = 0;
	virtual ~IInterpolator() {}
};

class CIDWInterpolator : public IInterpolator
{
public:
	CIDWInterpolator();
	virtual ~CIDWInterpolator();
	virtual void Initialize(IDataProvider* _pProvider);
	virtual float Interpolate(void* pos);

private:
	IDataProvider* pProvider;
};

class CKrigingInterpolator : public IInterpolator
{
public:
	CKrigingInterpolator();
	~CKrigingInterpolator();

	virtual void Initialize(IDataProvider* _pProvider);
	virtual float Interpolate(void* pos);

protected:
	typedef enum EVariogramMode
	{
		EVariogramModeSphere = 0, 
		EVariogramModeExponent
	};

	void CalculateCoeffs();
	float CalculateVariogram(EVariogramMode eMode, float h);
	void SolveMatrixEquation(const float* d, float* w);

private:
	IDataProvider* pProvider;
	float c0, c1, a;
	CArray2D<float>* pv;
	float* pd;
	float* pw;

	typedef struct
	{
		float fVarigram;
		float fSumOfWeight;
		int nCount;
	}SVarigramData;
};